package com.example.graduationdesignbackend.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MvcConfig implements WebMvcConfigurer {
  private String filePath = "D:/test/my/file/image/";
  @Override
  public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
      .allowedOriginPatterns("*")
      .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
      .allowedHeaders("*")
      .allowCredentials(true);
  }
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //将前者的路径映射到后者的static路径
    registry.addResourceHandler("/images/**").addResourceLocations("file:" + filePath);
    System.out.println("静态资源获取");
  }
}
